#ifndef __MCU_HARDWARE_SPI_H
#define __MCU_HARDWARE_SPI_H

#include "headfile.h"

typedef enum
{
    SPI_Mode_Hard,
    SPI_Mode_Soft
} SPI_mode;

class SPI
{
private:
    Hardware_SPI spi_hard;
    // Software_SPI spi_soft;
    SPI_mode mode;
    boolean is_init;

public:
    SPI(SPI_enum spi_e, SPI_clock_mode c_mode = CPOL_HIGH_CPHA_HIGH, int speed = MAX_HARDWARE_SPI_SPEED)
    {
        is_init = 0;
        spi_hard.cs = Pin_null;
        spi_hard.speed = speed;
        spi_hard.spi = spi_e;
        spi_hard.c_mode = c_mode;
        mode = SPI_Mode_Hard;
    }
    SPI(){};
    ~SPI(){};

    int begin();
    int end();

    void loadSlave(Pin_enum);
    void deloadSlave();

    size_t write(uint8_t);
    size_t write(const uint8_t *, size_t);
    size_t write(uint8_t, size_t);
    uint16_t read();
    size_t read(uint8_t *, size_t);

    size_t write16(uint16_t);
    size_t write16(const uint16_t *, size_t);
    size_t write16(uint16_t, size_t);
    uint16_t read16();
    size_t read16(uint16_t *, size_t);
};

#endif
